<template>
  <div>
    <el-table :data="filteredCourses" style="width: 100%">
      <el-table-column label="课程ID" prop="id" />
      <el-table-column label="课程名称" prop="name" />
      <el-table-column label="学时" prop="time" />
      <el-table-column label="学分" prop="point" />
      <el-table-column align="right">
        <template #header>
          <el-input v-model="keyword" size="small" placeholder="搜索课程" />
        </template>
        <template #default="scope">
          <el-button size="small" @click="handleEdit(scope.row)">
            编辑
          </el-button>
          <el-button size="small" type="danger" @click="handleDelete(scope.row)">
            删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 添加/编辑课程的对话框 -->
    <el-dialog :title="dialogTitle" v-model="dialogVisible" width="30%">
      <el-form :model="currentCourse" label-width="80px">
        <el-form-item label="课程名称">
          <el-input v-model="currentCourse.name"></el-input>
        </el-form-item>
        <el-form-item label="学时">
          <el-input v-model="currentCourse.time"></el-input>
        </el-form-item>
        <el-form-item label="学分">
          <el-input v-model="currentCourse.point"></el-input>
        </el-form-item>
      </el-form>
      <template #footer>
        <el-button @click="dialogVisible = false">取消</el-button>
        <el-button type="primary" @click="handleSave">保存</el-button>
      </template>
    </el-dialog>

    <!-- 添加课程按钮 -->
    <el-button type="primary" @click="handleAddCourse" style="margin-top: 20px;">
      添加课程
    </el-button>
  </div>

</template>

<script>
export default {
  name: "CourseView"
}
</script>

<style scoped>
  h2 {
    margin-bottom: 20px;
  }
</style>